package cn.itcast.service.impl;

import cn.itcast.dao.AddressDao;
import cn.itcast.entity.PageResult;
import cn.itcast.entity.QueryPageBean;
import cn.itcast.pojo.Address;
import cn.itcast.service.AddressService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AddressServiceImpl implements AddressService {


    @Autowired
    private AddressDao addressDao;

    //分页条件查询查询
//    @Override
//    public PageResult pageQuery(QueryPageBean queryPageBean) {
//        Integer currentPage = queryPageBean.getCurrentPage();
//        Integer pageSize = queryPageBean.getPageSize();
//        String queryString = queryPageBean.getQueryString();
//        PageHelper.startPage(currentPage, pageSize);
//        Page<Address> page = addressDao.selectByCondition(queryString);
//        long total = page.getTotal();
//        List<Address> result = page.getResult();
//        return new PageResult(total, result);
//    }




    /**
     * 查询所有列表
     * @return
     */
    @Override
    public List<Address> findAll() {
        //
     return addressDao.findAll();

    }

    /**
     * 新增分院
     */
    @Override
    public void add(Address address) {
            //判断 address.getId() 没有就添加  有就更新
        if( address.getId()==  null){
            addressDao.add(address);
        }
        else {
            update(address);
        }
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void deleteById(int id) {
        addressDao.deleteById(id);
    }

    /**
     * 更新
     * @param address
     */
    @Override
    public void update(Address address) {

        addressDao.update(address);
    }

    /**
     * 根据ID 查找
     * @param id
     * @return
     */
    @Override
    public Address findById(Integer id) {
      return   addressDao.findById(id);

    }

    /**
     * 改变按钮
     * @param id
     */
    @Override
    public void change(int id) {
            //通过ID调用sql语句的update方法
        addressDao.change(id);

    }


}
